package main

import (
	"fmt"
	"sync"
	"time"
)

func main() {
	// mutex[互斥，互斥锁]
	mutex := sync.Mutex{}

	go func() {
		//当有一个协程获得锁之后，会一直执行到次协程完毕，才会释放锁
		mutex.Lock()
		defer mutex.Unlock()
		for i := 1; i <= 5; i++ {
			time.Sleep(time.Millisecond)
			fmt.Println(i)
		}
	}()

	go func() {
		mutex.Lock()
		defer mutex.Unlock()
		for i := 1; i <= 5; i++ {
			time.Sleep(time.Millisecond)
			fmt.Println(i * 10)
		}
	}()
	//因此此系统会有序输出数字
	time.Sleep(time.Second)
}
